<template>
  <div class="update-gender">
    <van-picker
      title="性别"
      show-toolbar
      :columns="columns"
      :default-index="value"
      @confirm="onConfirm"
      @cancel="$emit('close')"
    />
  </div>
</template>

<script>
import { upDateUSerProfile } from '@/api/user'
export default {
  name: 'UpdateGender',
  components: {

  },
  props: {
    value: {
      type: Number,
      required: true
    }
  },
  data () {
    return {
      columns: ['男', '女']
    }
  },
  created () {

  },
  methods: {
    async onConfirm (data, index) {
      // console.log(data, index)
      this.$toast.loading({
        message: '修改中...',
        forbidClick: true,
        duration: 0
      })
      await upDateUSerProfile({
      //   gender: this.columns.indexOf(data)
        gender: index
      })

      // this.$emit('input', this.columns.indexOf(data))
      this.$emit('input', index)
      this.$emit('close')
      this.$toast.success('修改成功')
    }
  }
}
</script>

<style lang="less" scoped>
</style>
